/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rnavigator.view;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;
import rnavigator.model.Structure;

/**
 *
 * @author Elias la Cour
 */
public class View extends JPanel {

    private static int CANVAS_SIZE = 512;
    private Structure structure = null;
    final static BasicStroke stroke = new BasicStroke(1.0f);
    private boolean debug = true;
    boolean firstRun = true;
    JPanel content = new JPanel();
    JFrame topFrame = new JFrame();
    private StructurePanel structurePanel = new StructurePanel();

    public View() {
    }

    public View(Structure structure) {
        this.structure = structure;
    }

    public void createFramework() {
        topFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        topFrame.setSize(CANVAS_SIZE, CANVAS_SIZE);
        topFrame.setTitle("RNAvigator");
        this.setPreferredSize(new Dimension(CANVAS_SIZE, CANVAS_SIZE));
        //topFrame.pack();
        //topFrame.add(new MyCircle(new InputHandler().smallInput()));
        topFrame.setVisible(true);
        structurePanel=new StructurePanel();
        topFrame.add(structurePanel);
        //topFrame.setContentPane(content);
    }

    

    @Override
    protected void paintComponent(Graphics g) {
        //super is called to avoid visual artifacts. See javadoc for paintComponent
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        if (debug) {
            System.out.println("paintComponentmethod started");
        }
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(Color.BLUE);
        g2d.setStroke(stroke);
        g2d.drawString("a", 25, 25);
        int xMiddle;
        int yMiddle;
        xMiddle = getWidth() / 2;
        yMiddle = getHeight() / 2;
        int xStart;
        int yStart;
        xStart = getWidth() / 8;
        yStart = getHeight() / 2;
          if (debug){
        if (structure == null) {
            System.out.println("structure in view class == null");
        }
          }

        if (structurePanel != null) {
            System.out.println("structure in view class != null");

//            g2d.setColor(Color.red);
            //repaint();
        }
    }
//
//    public void drawLinearFeynman() {
//
//        String[] baseSequence = structure.getBaseSequence();
//
//        if (debug) {
//            System.out.println("drawLinearFeynman()");
//        }
//        for (int i = 1; i < baseSequence.length; i++) {
//            int x = 10 * i;
//            //String s = Character.toString(baseSequence[i]);
//            //g2d.drawString(s, x, 250);
//            //         drawElement(baseSequence[i], x, 250, g2d);
//            //repaint();
//        }
//        LinkedList<Base> knots = structure.getKnots();
//
////        while (!knots.isEmpty()) {
////            Knot k = knots.pop();
////            int b1X = k.getB1().getX();
////            int b2X = k.getB2().getX();
////            drawArc(b1X, (b2X - b1X), 100, g2d);
////        }
//    }

    /**
     * 
     * @param x
     * @param width
     * @param height
     * @param g2 
     */
//    private void drawArc(int x, int width, int height, Graphics2D g2d) {
//        int y = 180;
//        g2d.draw(new Arc2D.Double(x, y, width, height, 0, 180, Arc2D.OPEN));
//    }
    /**
     * @param structure the structure to set
     */
    public void setStructure(Structure structure) {
        this.structure = structure;
        structurePanel.setStructure(structure);
    }

    /**
     * @param debug the debug to set
     */
    public void setDebug(boolean debug) {
        this.debug = debug;
        structurePanel.setDebug(debug);
    }

    /**
     * @return the structurePanel
     */
    public StructurePanel getStructurePanel() {
        return structurePanel;
    }

    /**
     * @param structurePanel the structurePanel to set
     */
    public void setStructurePanel(StructurePanel structurePanel) {
        this.structurePanel = structurePanel;
    }
}
